package com.szss.springbootfirst.service.impl;

import com.szss.springbootfirst.config.RabbitMQConfig;
import com.szss.springbootfirst.entity.Email;
import com.szss.springbootfirst.mapper.EmailMapper;
import com.szss.springbootfirst.service.IEmailService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wcx
 * @date 2023/2/10 16:08
 */

@Service
public class EmailServiceImpl implements IEmailService {

    @Autowired
    private EmailMapper emailMapper;

    @Resource
    private RabbitTemplate rabbitTemplate;

    @Scheduled(cron = "0 */1 * * * ?")
    @Override
    public void findAll() {
        List<Email> emailList = emailMapper.findAll();

        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_DIRECT,RabbitMQConfig.EMAIL_KEY,emailList);
    }
}
